
** plot distribution of pollution 

***Inputs:
* $Data/GameUserWPdaily_norm.dta
* $Data/maxmindirectionsmonth_zip260.dta

***Outputs:
* $Results/hist_pm2.png
* $Results/hist_pm3.png


	capture eststo clear
	
	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)
	
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	gen tempsq = weighted_temperature* weighted_temperature
	
	

	egen cut_age = cut(age), at(15(10)85)

	egen cut_temp = cut(weighted_temperature), at(-40(10)40)

	egen cut_play = cut(nth_play), at(0 5 10 20 30 40 50)
	
	gen highplay = nth_play >=20
	gen old = age>50
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360	
	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection ==.
		
	
	keep if maxzipwind<. 
	
	
	
*** PLOT POLLUTION ***
	
	
	
	hist weighted_dailypm if weighted_dailypm <12 , freq bcolor(green) xscale(range(0 300))  legend(order(1 "Good" 2 "Moderate" 3 "Unhealthy Sensitive Groups" 4 "Unhealthy" 5 "Very Unhealthy" 6 "Hazardous") ring(0) bplacement(neast) bmargin(0))  xtitle("Daily PM2.5")  ///
	addplot(hist weighted_dailypm if weighted_dailypm >12 & weighted_dailypm<=35 , freq bcolor(yellow) || hist weighted_dailypm if weighted_dailypm >35 & weighted_dailypm<=55.5 , freq bcolor(orange)   ||  hist weighted_dailypm if weighted_dailypm >55.5 & weighted_dailypm<=150.5 , freq bcolor(red)  || hist weighted_dailypm if weighted_dailypm >150.5 & weighted_dailypm<=250, freq bcolor(purple)  || hist weighted_dailypm if weighted_dailypm >250 & weighted_dailypm<=500, freq bcolor(maroon) xline(25)) 
	
	
		graph export $Results/hist_pm2.png, replace


	
	
	hist weighted_dailypm if weighted_dailypm > 25 & weighted_dailypm<=35 , freq bcolor(yellow) xscale(range(35 300)) xlabel(25 100 200 300)  legend(order(1 "Moderate" 2 "Unhealthy Sensitive Groups" 3 "Unhealthy" 4 "Very Unhealthy" 5 "Hazardous") ring(0) bplacement(neast) bmargin(0))  xtitle("Daily PM2.5")  ///
	addplot(hist weighted_dailypm if weighted_dailypm >35 & weighted_dailypm<=55.5 , freq bcolor(orange)   ||  hist weighted_dailypm if weighted_dailypm >55.5 & weighted_dailypm<=150.5 , freq bcolor(red)  || hist weighted_dailypm if weighted_dailypm >150.5 & weighted_dailypm<=250, freq bcolor(purple)  || hist weighted_dailypm if weighted_dailypm >250 & weighted_dailypm<=500, freq bcolor(maroon) )  
	
	
		graph export $Results/hist_pm3.png, replace

	
	
